//
//  YQVisitorLoginView.m
//  WeiboOC
//
//  Created by yang on 15/11/11.
//  Copyright © 2015年 yang. All rights reserved.
//
#import "YQVisitorLoginView.h"
@interface YQVisitorLoginView ()
@property (nonatomic, strong) UIImageView* circleView;
@property (nonatomic, strong) UIImageView* backView;
@property (nonatomic, strong) UIImageView* iconView;
@property (nonatomic, strong) UILabel* label;

@end
@implementation YQVisitorLoginView
//懒加载子控件
- (UIImageView*)circleView
{
    if (!_circleView) {
        UIImageView* circleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_smallicon"]];
        _circleView = circleView;
    }
    return _circleView;
}
- (UIImageView*)backView
{
    if (!_backView) {
        UIImageView* backView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"visitordiscover_feed_mask_smallicon"]];
        _backView = backView;
    }
    return _backView;
}
- (UIImageView*)iconView
{
    if (!_iconView) {
        UIImageView* iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_house"]];
        _iconView = iconView;
    }
    return _iconView;
}
- (UILabel*)label
{
    if (!_label) {
        UILabel* label = [[UILabel alloc] initWithTitle: @"关注一些人，回这里看看有什么,惊喜关注一些人，回这里看看有什么惊喜" size:14 color:[UIColor lightGrayColor] margin:0];
        _label = label;
    }
    return _label;
}
- (UIButton*)loginButton
{
    if (!_loginButton) {
        UIButton* loginButton = [[UIButton alloc] initWithTitle:@"登陆" backImage:@"common_button_white_disable" color:[UIColor lightGrayColor] image:nil size:0];
        _loginButton = loginButton;
    }
    return _loginButton;
}
- (UIButton*)registerButton
{
    if (!_registerButton) {
        UIButton* registerButton = [[UIButton alloc] initWithTitle:@"注册" backImage:@"common_button_white_disable" color:[UIColor lightGrayColor] image:nil size:0];
        _registerButton = registerButton;
    }
    return _registerButton;
}
//重新 init 方法
- (instancetype)init
{
    self = [super init];
    if (self) {

        [self addSubview:self.circleView];
        [self addSubview:self.backView];
        [self addSubview:self.iconView];
        [self addSubview:self.label];
        [self addSubview:self.loginButton];
        [self addSubview:self.registerButton];
    }
    return self;
}
- (void)setUIInfoImage:(NSString*)imageName title:(NSString*)title
{
    self.iconView.hidden = NO;
    self.label.text = title;
    if (imageName != nil) {
        self.circleView.image = [UIImage imageNamed:imageName];
        [self bringSubviewToFront:self.circleView];
        self.iconView.hidden = YES;
    }
    else {
        [self startAnimation];
    }
}
//旋转方法
- (void)startAnimation
{
    CABasicAnimation* basic = [[CABasicAnimation alloc] init];
    basic.keyPath = @"transform.rotation";
    basic.repeatCount = MAXFLOAT;
    basic.toValue = @(2.0 * M_PI);
    basic.duration = 20;
    basic.removedOnCompletion = NO;
    [self.circleView.layer addAnimation:basic forKey:nil];
}
//布局子控件
- (void)layoutSubviews
{
    [super layoutSubviews];
    [self.circleView makeConstraints:^(MASConstraintMaker* make) {
        make.centerX.equalTo(self);
        make.centerY.equalTo(self).offset(-60);
    }];
    [self.iconView makeConstraints:^(MASConstraintMaker* make) {
        make.centerX.centerY.equalTo(self.circleView);
    }];
    [self.label makeConstraints:^(MASConstraintMaker* make) {
        make.centerX.equalTo(self.circleView);
        make.top.equalTo(self.circleView.bottom).offset(26);
        make.height.equalTo(50);
        make.width.equalTo(224);
    }];
    [self.loginButton makeConstraints:^(MASConstraintMaker* make) {
        make.left.equalTo(self.label.left);
        make.top.equalTo(self.label.bottom).offset(16);
        make.height.equalTo(35);
        make.width.equalTo(100);
    }];
    [self.registerButton makeConstraints:^(MASConstraintMaker* make) {
        make.right.equalTo(self.label.right);
        make.top.equalTo(self.label.bottom).offset(16);
        make.height.equalTo(35);
        make.width.equalTo(100);
    }];
    [self.backView makeConstraints:^(MASConstraintMaker* make) {
        make.left.right.equalTo(self);
        make.top.equalTo(self);
        make.bottom.equalTo(self.loginButton.bottom);
    }];
    self.backgroundColor = [UIColor colorWithWhite:0.93 alpha:1];
}
@end
